<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <input type="text" v-focus>

        <div v-mytext="msg"></div>
    </div>
    <script src="./node_modules/vue/dist/vue.js"></script>
    <script>

        Vue.directive("focus", {
            inserted(el, binding){
                //如果要在元素被插入页面之后做什么事情，就得再inserted中实现
                el.focus();
            }
        })

        // Vue.directive("mytext", {
        //     bind(el, binding){
        //         el.innerText = binding.value;
        //     }
        // })

        var vm = new Vue({
            el: "#app",
            data: {
                msg: "xyz"
            },
            directives: {
                // 指令名称: {
                //     bind(){}
                // }
                focus:{
                    inserted(el){
                        el.focus();
                    }
                }
            }
        })
    </script>
</body>

</html>